package com.dw.etl.core.service;

import com.dw.etl.common.util.UUIDUtil;
import  com.dw.etl.common.vo.PaginationVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.MdMedPubfldService;
import com.dw.etl.core.mapper.MdMedPubfldMapper;
import com.dw.etl.core.bean.model.MdMedPubfld;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * mdMedPubfld服务实现类
 * Created by hozeData on 2021/07/05.
 */
@Service
@Transactional
public class MdMedPubfldServiceImpl implements MdMedPubfldService{

    private static final Logger LOGGER = LoggerFactory.getLogger(MdMedPubfldServiceImpl.class);

    @Autowired
    private MdMedPubfldMapper mdMedPubfldMapper;

    @Override
    public int insert(MdMedPubfld mdMedPubfld) {
        if(StringUtils.isEmpty(mdMedPubfld.getIdPubfld())){
            mdMedPubfld.setIdPubfld(mdMedPubfld.getCd());
        }
        return mdMedPubfldMapper.insert(mdMedPubfld);
    }

    @Override
    public int insertSelective(MdMedPubfld mdMedPubfld)  {
        if(StringUtils.isEmpty(mdMedPubfld.getIdPubfld())){
            mdMedPubfld.setIdPubfld(mdMedPubfld.getCd());
        }
        return mdMedPubfldMapper.insertSelective(mdMedPubfld);
    }

    @Override
    public int deleteById(String idPubfld)  {
        return mdMedPubfldMapper.deleteByPrimaryKey(idPubfld);
    }

    @Override
    public int updateByIdSelective(MdMedPubfld mdMedPubfld)  {

        return mdMedPubfldMapper.updateByPrimaryKeySelective(mdMedPubfld);
    }

    @Override
    public int updateById(MdMedPubfld mdMedPubfld)  {
        return mdMedPubfldMapper.updateByPrimaryKey(mdMedPubfld);
    }

    @Override
    public MdMedPubfld getById(String idPubfld)  {
        return mdMedPubfldMapper.selectByPrimaryKey(idPubfld);
    }

    @Override
    public List<MdMedPubfld> findByModel(MdMedPubfld mdMedPubfld)  {
        return mdMedPubfldMapper.findByModel(mdMedPubfld);
    }

    @Override
    public PaginationVO<MdMedPubfld> findPageByModel(MdMedPubfld mdMedPubfld, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<MdMedPubfld> quesList = mdMedPubfldMapper.findByModel(mdMedPubfld);
        PageInfo<MdMedPubfld> pageInfo = new PageInfo<>(quesList);
        PaginationVO<MdMedPubfld> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }

    @Override
    public PaginationVO<MdMedPubfld> findPageByLike(String filter, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<MdMedPubfld> quesList = mdMedPubfldMapper.findByLike(filter);
        PageInfo<MdMedPubfld> pageInfo = new PageInfo<>(quesList);
        PaginationVO<MdMedPubfld> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }

    @Override
    public List<MdMedPubfld> findByIdList(List<String> idList) {
        return mdMedPubfldMapper.findByIdList(idList);
    }

    @Override
    public String getCdDimgrp(List<String> idList) {
        List<MdMedPubfld> list = mdMedPubfldMapper.findByIdList(idList);
        String cdDimgrp = "";
        for(MdMedPubfld fld:list) {
            cdDimgrp += fld.getCd()+"_";
        }
        return cdDimgrp.substring(0,cdDimgrp.length()-1);
    }
}
